const merge = (A, m, B, n) => {
  let i = 0,
    j = 0,
    arr = []
  while (i < m || j < n) {
    if (A[i] < B[j] && A[i] !== 0) {
      arr.push(A[i])
      i += 1
    } else {
      arr.push(B[j])
      j += 1
    }
  }
  return arr
}

console.log(merge([1, 2, 3, 0, 0, 0], 3, [2, 5, 6], 3));